#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>


#define PORT 1234
//the max num to connect.
#define BACKLOG 1  


main(){

//printf("hello wolrd");
int listenfd,connectfd;
struct sockaddr_in server;
struct sockaddr_in client;
socklen_t addrlen;
/*create TCP socket*/

if((listenfd =socket(AF_INET,SOCK_STREAM,0))==-1){
	perror("socket error");
	exit(1);
}

/* set socket option*/

int opt=SO_REUSEADDR;
setsockopt(listenfd,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));
bzero(&server,sizeof(server));


server.sin_family=AF_INET;
server.sin_port=htons(PORT);
server.sin_addr.s_addr=htonl(INADDR_ANY);


if(bind(listenfd,(struct sockaddr*)&server,sizeof(server))==-1){
	perror("Bind() error");
	exit(1);

}


//len=sizeof(client);
printf("You got a connection from client's ip is %s,port is %d\n",inet_ntoa(client.sin_addr),htons(client.sin_port));


send(connectfd,"Welcome\n",8,0);
close(connectfd);
close(listenfd);












}
